package algo.A02_查找排序基础;

import util.ArrayUtil;

/**
 * 冒泡排序
 */
public class M02_BubbleSort {
    public static void main(String[] args) {
        int[] randomArr = ArrayUtil.getRandomArr(10, 0, 100);
        ArrayUtil.print(randomArr);
        bubbleSort(randomArr);
        ArrayUtil.print(randomArr);
    }

    public static void bubbleSort(int[] arr) {
        for (int tianHuaBan = arr.length - 1; tianHuaBan >= 0; tianHuaBan--) {
            for (int j = 0; j < arr.length - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
}
